-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added the ability to reflect Inductive definitions #32
Conversation
Just created a new vernac command "Make Inductive". As of now, it does nothing. Tested the dummy command in demo.v
The body is ignored for now. Tested this part in demo.v
The name and arity are obtained properly populated. However the resultant definition changes arity from Set to Prop.
Found the correct input by snooping on the paramcoq plugin (using coq/dev/top_printer.ml) Also, needed to recompile coq so that top_printer.ml gets included in coqtop/coqc: coq/dev$ echo "Top_printer" > printer.mllib then add dev/printer.cma to $CORECMA in coq/Makefile.common
Thanks for the PR. This is a great feature to have. Is there a reason that you chose not to use the existing quoting of inductive types? In particular (https://github.com/gmalecha/template-coq/blob/master/theories/Ast.v#L63) Does it not contain enough information? My worry with exposing such low level types is two fold:
|
That information is not sufficient, as pointed out by Jason: All the fields in |
I don't doubt that they are semantically relevant, it just seems like it is a representation that is not natural to Coq users. To address the problem that @JasonGross pointed out, would it be sufficient to add a type to the inductive as a whole? Something like:
My worry is that everyone that uses this library is going to have to reverse engineer what this type does. A better solution (if it can be made to work) would be to have something that maps more directly to how Coq users write inductive types. |
I did have some difficulty in figuring out the de-bruijn indices for the types of constructors. Your suggested representation still loses information that is relevant to me (parameters vs indices, flags for template/universe polymorphism). |
I believe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @gmalecha that it would be nicer to find a way to merge this info in PType somehow, otherwise we have a strange redundancy. Currently template-coq has this "program" datatypes that does not correspond to something in Coq. Why not switch to an env + term representation here?
Then the inductive decls and global definitions would be in the env. We could make a compatibility layer that would produce a [program] from those.
|
||
|
||
Definition local_entry : Set := term. | ||
(* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not LocalDef and LocalAssum here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does LocalDef
stand for local let bindings?
|
||
Record mutual_inductive_entry : Set := { | ||
mind_entry_record : option (option ident); | ||
(* mind_entry_finite : Decl_kinds.recursivity_kind; (* inductive/coinductive/record*)*) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the finiteness information can be useful (ind vs coind in particular)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I was being lazy.
mind_entry_params : list (ident * local_entry); | ||
mind_entry_inds : list one_inductive_entry; | ||
mind_entry_polymorphic : bool; | ||
(* mind_entry_universes : Univ.universe_context; (*what is this?*) *) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the universe context of the inductive: either global universes and constraints that must be declared or local in case of universe polymorphism (it records the universe binders of all the inductives/constructors in that case). This is not handled by template-coq anywhere currently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a lot of issues trying to get this to work due to the way that Coq represents universes. Issue #1 is about universes. If you have any thoughts on how to reify and reflect universes, I think that is the biggest problem with template-coq right now.
mind_entry_inds : list one_inductive_entry; | ||
mind_entry_polymorphic : bool; | ||
(* mind_entry_universes : Univ.universe_context; (*what is this?*) *) | ||
mind_entry_private : option bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed private is for the HIT trick
I think then env + term representation would be a good route to go here. At minimum this would mean pulling the constructors of program out and make them the environment values. @mattam82 I got confused about the last comment in your comment. Do you think that we should convert these new definitions to something like PType in Gallina, or in the plugin? |
@gmalecha in Gallina, as part of the plugin's v files we could have an env + term -> program function to get back the closed representation. |
Yes
…On Fri, Dec 2, 2016 at 5:14 PM Abhishek Anand ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In theories/Ast.v <#32>:
> @@ -63,3 +63,34 @@ Inductive program : Set :=
list (ident * inductive_body) -> program -> program
| PAxiom : ident -> term (* the type *) -> program -> program
| PIn : term -> program.
+
+
+(* representation of mutual inductives. copied, more or less, from Coq/kernel/entries.mli
+*)
+
+Record one_inductive_entry : Set := {
+ mind_entry_typename : ident;
+ mind_entry_arity : term;
+ mind_entry_template : bool; (* template polymorphism ? *)
+ mind_entry_consnames : list ident;
+ mind_entry_lc : list term}.
+
+
+Definition local_entry : Set := term.
+(*
Does LocalDef stand for local let bindings?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#32>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAGARSu5ImchGCkEzBJIq0dfim9Ls2OCks5rEEPkgaJpZM4LCCXt>
.
|
mind_entry_private := None; | ||
|}. | ||
|
||
(* Make Inductive ltac:(let t:= eval compute in mut_i in exact t). *) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this perform reduction so that we don't need to use tactics in terms to make it work? I don't know precisely how to do this, but I'm certain that @mattam82 could tell us in a minute.
| Finite | ||
| CoFinite | ||
| BiFinite | ||
*) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like an out-of-place comment.
| LocalDef of constr | ||
| LocalAssum of constr | ||
*) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(** The kind of definition. See kerne/....mli **)
type local_entry = | ||
| LocalDef of constr | ||
| LocalAssum of constr | ||
*) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like the next comment.
VERNAC COMMAND EXTEND Unquote_inductive CLASSIFIED AS SIDEFF | ||
| [ "Make" "Inductive" constr(def) ] -> | ||
[ check_inside_section () ; | ||
let (evm,env) = Lemmas.get_current_context () in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to check_inside_section
here?
@@ -766,6 +826,14 @@ VERNAC COMMAND EXTEND Unquote_vernac CLASSIFIED AS SIDEFF | |||
[] None result None (Lemmas.mk_hook (fun _ _ -> ())) ] | |||
END;; | |||
|
|||
(* get rid of the unused ident(name)? *) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this mean?
Merging! |
Rename Constraint to ConstraintSet
This is implemented as the command
Make Inductive
.See demo.v for a demo.